﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using ChinaSoft.DBUtility;//Please add references
namespace ChinaSoft.DAL.Common
{
    public class SerialNumber
    {
        /// <summary>
        /// 生成流水号
        /// </summary>
        /// <param name="TableName"></param>
        /// <param name="SNID"></param>
        /// <param name="QianZhui"></param>
        /// <param name="Numberlength"></param>
        /// <returns></returns>
        public string GetSerialNumber(string TableName, string SNID, string QianZhui, int Numberlength)
        {
            string idString = DbHelperOra.GetSingle("select max(" + SNID + ") from " + TableName).ToString();
            int startNum = 0;
            if (idString.Length >= (QianZhui.Length + Numberlength))
                startNum = Convert.ToInt32(idString.Substring(QianZhui.Length, (idString.Length - QianZhui.Length))) + 1;
            string startString = null;
            if (startNum < Numberlength)
                startString = startNum.ToString().PadLeft(Numberlength + 1 - startNum.ToString().Length, '0').Trim();
            return (QianZhui + startString);
        }
    }
}
